package cn.tedu.springboot.controller;

import cn.tedu.springboot.base.response.JsonResult;
import cn.tedu.springboot.base.response.StatusCode;
import cn.tedu.springboot.mapper.UserMapper;
import cn.tedu.springboot.pojo.dto.UserAddParam;
import cn.tedu.springboot.pojo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.logging.Log;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
	@Autowired
	private UserMapper userMapper;
	@RequestMapping("/add")
	public JsonResult add(@RequestBody UserAddParam userAddParam) {
		log.debug("添加用户业务 ："+ userAddParam);
		User user = new User();
		BeanUtils.copyProperties(userAddParam, user);
		user.setCreateTime(new Date());
		log.debug("实体类 ："+ user);
		int i = userMapper.insertUser(user);
		if (i > 0){
			return JsonResult.ok();
		}
		return new JsonResult(StatusCode.OOPERATION_FAILED);
	}
}
